<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
</head>
<style>
    .none_tip {
        color: #565656;
        font-size: 0.7rem;
        margin: 10rem auto;
        text-align: center;
    }

    .bottom_div {
        width: 100%;
        height: 6.5rem;
        background-color: #fff;
        position: fixed;
        bottom: 0;
        left: 0;
    }

    .bottom_div .img_item {
        width: 25%;
        display: inline-block;
        margin-left: -0.25rem;
        height: 2rem;
        text-align: center;
        color: #565656;
        font-size: 0.6rem;
        /* margin-top: 0.5rem; */
    }


    .bottom_div .img_item img {
        width: 1rem;
        height: 1rem;
        margin: 0.5rem 0 0.5rem 0;
    }

    .bottom_div .input {
        padding: 0 1rem;
        position: relative;
    }

    .bottom_div .input input {
        margin-top: 1.5rem;
        width: 95%;
        padding-left: 5%;
        height: 2rem;
        background-color: #F7F7F7;
        font-size: 0.7rem;
        color: #565656;
        border-radius: 0.5rem;
        outline: none;
    }

    .bottom_div .input button {
        outline: none;
        position: absolute;
        width: 4rem;
        height: 2rem;
        background-color: #2780e8;
        font-size: 0.7rem;
        color: #fff;
        border-radius: 0.5rem;
        right: 1rem;
        bottom: 0;
    }

    .yaocai_div {
        padding: 0 0.8rem;
    }

    .yaocai_total {
        text-align: center;
        /* background-color: #2780e8; */
        color: #2780e8;
        height: 1rem;
        line-height: 1rem;
        width: 100%;
        font-size: 0.7rem;
        margin-bottom: 0.5rem;
    }

    .yaocai_div .yaocai_div_item {
        width: 8.45rem;
        height: 2rem;
        display: inline-block;
        border: 1px solid #E8E8E8;
        border-top: none;
        position: relative;
    }

    .yaocai_div .yaocai_div_item img {
        width: 0.8rem;
        height: 0.8rem;
        position: absolute;
        top: 0.6rem;
        left: 0.5rem;
    }

    .yaocai_div .yaocai_div_item .yaocai_name {
        font-size: 0.7rem;
        color: #565656;
        position: absolute;
        top: 0.45rem;
        left: 1.7rem;
    }

    .yaocai_div .yaocai_div_item .yaocai_num {
        position: absolute;
        width: 2.7rem;
        height: 1rem;
        line-height: 1rem;
        top: 0.5rem;
        right: 0.5rem;
        color: #565656;
        font-size: 0.7rem;
    }

    .yaocai_div .yaocai_div_item .yaocai_num input {
        border-bottom: 1px solid #E8E8E8;
        width: 1.5rem;
        height: 100%;
        outline: none;
        margin-right: 0.3rem;
        text-align: center;
        color: #565656;
        font-size: 0.7rem;
    }

    .yaocai_div .yaocai_div_item:nth-child(1),
    .yaocai_div .yaocai_div_item:nth-child(2) {
        border-top: 1px solid #E8E8E8;
    }

    .yaocai_div .yaocai_div_item:nth-child(2n) {
        margin-left: -0.25rem;
        border-left: none;
    }

    .yaocai_div .tips {
        font-size: 0.6rem;
        text-align: center;
        height: 2rem;
        line-height: 2rem;
    }

    .add_num_zhezhao,
    .lack_yaocai_zhezhao,
    .special_yaocai_zhezhao {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.7);
        z-index: 10;
    }

    .special_yaocai_zhezhao_ming {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        z-index: 10;
        background-color: rgba(0, 0, 0, 0.7);
    }

    .add_num_zhezhao .add_num_main {
        width: 13rem;
        margin: 10rem 0 0 3rem;
        background-color: #fff;
        text-align: center;
        border-radius: 1rem;
    }

    .add_num_zhezhao .add_num_main .add_num_title {
        padding: 1.2rem 0 0.4rem 0;
        color: #565656;
        font-size: 0.8rem;
    }

    .add_num_zhezhao .add_num_main .add_num_subtitle {
        color: #565656;
        font-size: 0.6rem;
        padding: 0.4rem 0 1rem 0;
    }

    .add_num_zhezhao .add_num_main .jiliang {
        padding: 0 2rem;
    }

    .add_num_zhezhao .add_num_main .jiliang p {
        width: 100%;
        height: 1.7rem;
        line-height: 1.7rem;
        font-size: 0.7rem;
        text-align: left;
        padding-bottom: 0.5rem;
    }

    .add_num_zhezhao .add_num_main .jiliang p span {
        float: right;
    }

    .add_num_zhezhao .add_num_main .jiliang p span img {
        width: 0.7rem;
        height: 0.7rem;
    }

    .add_num_zhezhao .add_num_main .jiliang p span input {
        width: 2rem;
        height: 1rem;
        border-bottom: 1px solid #565656;
        text-align: center;
        outline: none;
    }

    .add_num_zhezhao .btn_div {
        height: 2rem;
        line-height: 2rem;
        font-size: 0.7rem;
        border-top: 1px solid #E8E8E8;
    }

    .add_num_zhezhao .btn_div div {
        width: 50%;
        display: inline-block;
        text-align: center;
        margin-top: -0.1rem;
    }

    .add_num_zhezhao .btn_div div:last-child {
        color: #2780e8;
        margin-left: -0.25rem;
        border-left: 1px solid #E8E8E8;
    }

    .lack_yaocai_zhezhao .lack_yaocai_main {
        width: 16.25rem;
        margin: 10rem 0 0 1.25rem;
        background-color: #fff;
        height: 10rem;
    }

    .lack_yaocai_zhezhao .lack_yaocai_main .lack_title {
        padding: 1rem 0 0.5rem 1rem;
        color: #565656;
        font-size: 0.8rem;
        font-weight: bold;
        font-family: PingFangSC;
    }

    .lack_yaocai_zhezhao .lack_yaocai_main .lack_main {
        padding: 0 1rem;
        color: #838383;
        font-size: 0.7rem;
        line-height: 1rem;
    }

    .lack_yaocai_zhezhao .lack_yaocai_main .lack_yaocai {
        padding: 1rem 0 1.5rem 1rem;
        color: #838383;
        font-size: 0.7rem;
    }

    .lack_yaocai_zhezhao .lack_yaocai_main .lack_yaocai span {
        color: #2780e8;
    }

    .lack_yaocai_zhezhao .lack_yaocai_main .btn_div span {
        float: right;
        padding: 0 1rem 0rem 1rem;
        color: #565656;
        font-size: 0.7rem;
    }

    .lack_yaocai_zhezhao .lack_yaocai_main .btn_div span:last-child {
        color: #838383;
    }

    .special_yaocai_main {
        width: 16.25rem;
        margin: 10rem 0 0 1.25rem;
        background-color: #fff;
    }

    .special_yaocai_main_fanan {
        width: 16.25rem;
        height: 7rem;
        margin: 10rem 0 0 1.25rem;
        background-color: #fff;
        font-size: 16px;
        padding: 2rem 0;
    }

    .special_yaocai_main .special_yaocai_title {
        padding: 1rem 0 0 1rem;
        color: #565656;
        font-size: 0.8rem;
        font-family: PingFangSC;
        font-weight: bold;
    }

    .special_yaocai_main .special_yaocai_tip {
        padding: 0.5rem 0 0.3rem 1rem;
        color: #838383;
        font-size: 0.7rem;
    }

    .special_yaocai_main .special_yaocai {
        color: #2780e8;
        font-size: 0.7rem;
        padding: 0rem 0 1rem 1rem;
    }

    .special_yaocai_main .checked_div {
        height: 2rem;
        position: relative;
        font-size: 0.7rem;
        color: #838383;
    }

    .special_yaocai_main .checked_div img {
        position: absolute;
        width: 1rem;
        height: 1rem;
        top: 0.5rem;
        left: 1rem;
    }

    .special_yaocai_main .checked_div .checked_div_title {
        position: absolute;
        left: 2.5rem;
        top: 0;
    }

    .special_yaocai_main .checked_div .checked_div_subtitle {
        font-size: 0.6rem;
        color: #2780e8;
        position: absolute;
        bottom: 0;
        left: 2.5rem;
    }

    .special_yaocai_main .btn_div {
        height: 2.7rem;
    }

    .special_yaocai_main .btn_div span {
        float: right;
        padding: 1rem;
        font-size: 0.7rem;
    }

    .special_yaocai_main .btn_div span:first-child {
        color: #838383;
    }

    .searchReslut {
        width: 100%;
        position: absolute;
        top: -3rem;
        display: -webkit-box;
        overflow-x: scroll;
        -webkit-overflow-scrolling: touch;
    }

    .searchReslut .item {
        box-sizing: border-box;
        background-color: #fff;
        /* line-height: 1.5rem; */
        height: 3rem;
        width: 25%;
        font-size: 0.7rem;
        border: 1px solid #e8e8e8;
        border-left: none;
        text-align: center;
    }

    .searchReslut .item p {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        margin-top: 0.4rem;
    }

    .searchReslut .item .item_price {
        color: #2780e8;
        font-size: 0.6rem;
    }

    .price_zhezhao {
        width: 100%;
        height: 100%;
        position: fixed;
        top: 0;
        left: 0;
        background-color: rgba(0, 0, 0, 0.7);
    }

    .price_zhezhao .price_zhezhao_main {
        width: 16.25rem;
        margin-left: 1.25rem;
        margin-top: 7.5rem;
        background-color: #fff;
    }

    .price_zhezhao .price_zhezhao_main .price_title {
        padding: 1rem 0 1rem 1rem;
        color: #565656;
        font-size: 0.8rem;
    }

    .price_zhezhao .price_zhezhao_main .price_div {
        padding: 0 1rem;
        overflow-y: auto;
        max-height: 11rem;
        min-height: 4rem;
    }

    .price_zhezhao .price_zhezhao_main .price_div .price_div_item {
        line-height: 2rem;
        color: #565656;
        font-size: 0.7rem;
    }

    .price_zhezhao .price_zhezhao_main .price_div .price_div_item span {
        color: #2780e8;
    }

    .price_zhezhao .price_zhezhao_main .price_div input {
        line-height: 2rem;
        color: #565656;
        font-size: 0.7rem;
        outline: none;
        border-bottom: none;
    }

    .price_zhezhao .price_zhezhao_main .btn_div {
        width: 100%;
        height: 3rem;
        line-height: 3rem;
    }

    .price_zhezhao .price_zhezhao_main .btn_div span {
        width: 49%;
        display: inline-block;
        /* margin-left: -0.25rem; */
        text-align: center;
        color: #565656;
        font-size: 0.7rem;
    }

    .fanan_title {
        text-align: center;
        font-size: 20px;
        font-weight: 1000;
    }

    .fanan_input {
        display: flex;
        align-items: center;
        margin-left: 0.5rem;
        margin-top: 1rem;
    }

    .fanan_input_title {
        font-size: 18px;
    }

    .fanan_input_input {
        /* display: block; */
        margin-top: 0.1rem;
        margin-left: 0.3rem;
    }

    .fanan_button {
        display: flex;
        align-items: center;
        justify-content: center;
        margin-top: 2rem;
    }

    .fanan_quxiao {
        border-radius: 5px;
        width: 3rem;
        height: 1.5rem;
        background-color: blanchedalmond;
        font-size: 12px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .fanan_queding {
        border-radius: 5px;
        width: 3rem;
        height: 1.5rem;
        background-color: red;
        color: white;
        font-size: 12px;
        display: flex;
        align-items: center;
        justify-content: center;
        margin-left: 0.4rem;
    }
</style>

<body>
    <div id="app" v-cloak>
        <div class="placeholder_div"></div>
        <p class="yaocai_total">{{notice_tip}}</p>
        <div class="yaocai_div">

            <div class="yaocai_div_item" v-for="(item,index) in total_yaocai">
                <img src="../image/icon_del.png" @click="del_total_yaocai(index)" alt="">
                <p class="yaocai_name">{{item.name}}</p>
                <div class="yaocai_num">
                    <input type="Number" v-model="item.quantity" @input="sent_data()">{{item.unit}}
                </div>
            </div>

            <p class="tips">已经没有更多了~</p>
        </div>

        <div class="bottom_div">
            <div class="img_item" @click="add_num_zhezhao = true">
                <img src="../image/icon_add_yaocai_3.png" alt="">
                <p>按倍改量</p>
            </div>
            <div class="img_item" onclick="save_yaocai_scheme()">
                <img src="../image/icon_add_yaocai_2.png" alt="">
                <p>存为常用方</p>
            </div>
            <div class="img_item openwin" data-win="my_always_useing_win" data-index="11">
                <img src="../image/icon_add_yaocai_1.png" alt="">
                <p>调用常用方</p>
            </div>

            <div class="img_item" onclick="del_yaocai()">
                <img src="../image/icon_add_yaocai_4.png" alt="">
                <p>清空药材</p>
            </div>

            <div class="input">
                <!-- <button class="confirm" v-if="yaocai != ''" v-show="yaocai!=' '">确定</button> -->
                <input type="text" v-model="yaocai" onkeyup="this.value=this.value.replace(/\s+/g,'')"
                    placeholder="请输入药材名、方名、克量">
            </div>
            <div class="searchReslut">
                <div class="item" v-if="yaocai != ''" v-show="yaocai!=' '" v-for="item in searchReslut"
                    @click="push_total_yaocai(item.name,item.id,item.drugsNo,item.salePrice,item.specs,item.storeId)"
                    onclick="get_focus()">
                    <p class="item_name">{{item.name}}</p>
                    <p class="item_price">￥{{item.salePrice}}元/g</p>
                </div>

            </div>
        </div>

        <div style="height: 7.5rem;width: 100%;"></div>
        <!-- 按倍改量弹出层 -->
        <div class="add_num_zhezhao" v-if="add_num_zhezhao">
            <div class="add_num_main">
                <p class="add_num_title">按倍改量</p>
                <p class="add_num_subtitle">所有药材按倍改量后将四舍五入取整</p>

                <div class="jiliang">
                    <p class="now_jiliang">当前总剂量 <span>{{total_quantity}}g</span></p>
                    <p class="alter_jiliang">修改后总剂量 <span>{{(num * total_quantity).toFixed(0)}}g</span></p>
                    <p class="alter_num">修改倍速
                        <span>
                            <img src="../image/icon_del1.png" @click="del_num" alt="">
                            <input type="number" readonly v-model="num">
                            <img src="../image/icon_add.png" @click="add_num" alt="">
                        </span>
                    </p>
                </div>


                <div class="btn_div">
                    <div @click="add_num_zhezhao = false">取消</div>
                    <div @click="add_total_quantity">保存</div>
                </div>
            </div>
        </div>

        <!-- 缺药提示弹出层 -->
        <div class="lack_yaocai_zhezhao" v-if="lack_yaocai_zhezhao">
            <div class="lack_yaocai_main">
                <p class="lack_title">缺药提示</p>
                <p class="lack_main">当前药房暂无法提供全部药材，您可修改药材或更换药房看看</p>
                <p class="lack_yaocai">药房缺药：<span>葛根</span></p>
                <div class="btn_div">
                    <span>更换药房</span>
                    <span>修改药材</span>
                </div>
            </div>
        </div>

        <!-- 特殊缺药签字确认弹出层 -->
        <div class="special_yaocai_zhezhao" v-if="special_yaocai_zhezhao">
            <div class="special_yaocai_main">
                <p class="special_yaocai_title">特殊药材签字确认</p>
                <p class="special_yaocai_tip">以下药材剂量已超过药典建议：</p>
                <p class="special_yaocai">葛根20g，葛根30g</p>
                <div class="checked_div">
                    <img @click="radio_cheched=radio_cheched?false:true"
                        :src="radio_cheched ? '../image/icon_radio_checked.png': '../image/icon_radio.png'" alt="">
                    <p class="checked_div_title">我确认以上药材无需修改</p>
                    <p class="checked_div_subtitle">*勾选后即可按此开方</p>
                </div>

                <div class="btn_div">
                    <span onclick="submit()">确定开方</span>
                    <span>修改药材</span>
                </div>
            </div>
        </div>

        <!-- 保存药材遮罩 -->
        <div class="price_zhezhao" v-if="price_zhezhao">
            <div class="price_zhezhao_main">
                <p class="price_title">确认药材</p>
                <div class="price_div">
                    <p class="price_div_item" v-for="item in total_yaocai">
                        {{item.name}} <span>{{item.salePrice}}元/g 共{{item.quantity}}g</span>
                        总共{{toThreeDecimal(item.salePrice * item.quantity)}}元
                    </p>
                </div>

                <div class="btn_div">
                    <span @click="price_zhezhao = false">取消</span>
                    <span style="color: #2E8EFF;" @click="queren">确定</span>
                </div>
            </div>
        </div>


        <!-- 存为常用方 -->
        <div class="special_yaocai_zhezhao_ming" v-if="special_yaocai_zhezhao_fanan">
            <div class="special_yaocai_main_fanan">
                <div class="fanan_title">
                    <p>存为常用方</p>
                </div>
                <div class="fanan_input">
                    <p class="fanan_input_title">常用方名称</p>
                    <input placeholder="请输入常用方名称" v-model="title_name" class="fanan_input_input">
                </div>
                <div class="fanan_button">
                    <div @click="special_yaocai_zhezhao_fanan = false" class="fanan_quxiao">取消</div>
                    <div @click="quding" class="fanan_queding">确定</div>
                </div>
            </div>
        </div>


    </div>
</body>

</html>
<script src="../script/set_root.js"></script>

<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/zepto.min.js"></script>
<script type="text/javascript" src="../script/hb.js"></script>
<script type="text/javascript" src="../script/vue.js"></script>
<script type="text/javascript">
    apiready = function () {
        hb_ready();
        // alert(String(api.pageParam.id))
        if (api.pageParam.index == 1) {
            app.total_yaocai = api.pageParam.total_yaocai
            app.total_quantity = 0 // 每次计算数量时都需要先置空
            for (var i = 0; i < app.total_yaocai.length; i++) {
                app.total_quantity += Number(app.total_yaocai[i].quantity)
            }
        }
        app.total_yaocai = api.pageParam.total_yaocai
        app.index = api.pageParam.index
        api.addEventListener({
            name: 'fasong_yaocai'
        }, function (ret, err) {
            // alert(JSON.stringify(ret.value.value))
            app.total_yaocai = ret.value.value
            app.sent_data()
            app.$nextTick(function () {
                hb_init_openwinby_click();
            })
        });

        api.addEventListener({
            name: 'queren_yaocai'
        }, function (ret, err) {
            // alert(JSON.stringify(app.total_yaocai))
            app.price_zhezhao = true
        });
    }
    //使用vue对数据进行绑定
    var app = new Vue({
        el: '#app',
        data: {
            add_num_zhezhao: false, // 按倍改量
            lack_yaocai_zhezhao: false, // 缺药提示
            special_yaocai_zhezhao: false, //特殊药材签字确认
            special_yaocai_zhezhao_fanan: false, //常用方名称
            radio_cheched: false, // 单选框选择确认
            yaocai: "", // 搜索关键词
            num: 1,
            index: 0,
            searchReslut: [], // 搜索出来的药材数组
            total_yaocai: [], // 总共的药材
            total_quantity: 0, // 全部药材共多少g
            string_total_yaocai: [], // 全部药材的string类型
            notice_tip: "",
            price_zhezhao: false,
            title_name: '', //常用方名称
        },
        methods: {
            toThreeDecimal: function (val) {
                return $api.toThreeDecimal(val)
            },

            // 按量改倍
            add_total_quantity: function () {
                for (var i = 0; i < this.total_yaocai.length; i++) {
                    this.total_yaocai[i].quantity = Number(this.total_yaocai[i].quantity) * this.num
                }
                this.add_num_zhezhao = false
                // 发送数据给win
                api.sendEvent({
                    name: 'total_yaocai',
                    extra: {
                        total_yaocai: this.total_yaocai
                    }
                });
            },
            queren: function () {
                // 点击了确认
                sendting("queren_ok")
            },
            // 发送数据
            sent_data: function (val) {
                app.total_quantity = 0 // 每次计算数量时都需要先置空
                for (var i = 0; i < app.total_yaocai.length; i++) {
                    app.total_quantity += Number(app.total_yaocai[i].quantity)
                }
                app.notice_tip = "请确认当前共" + app.total_yaocai.length + "味药材,共" + app.total_quantity + "g"

                // 发送数据给win
                api.sendEvent({
                    name: 'total_yaocai',
                    extra: {
                        total_yaocai: this.total_yaocai
                    }
                });
                app.$nextTick(function () {
                    hb_init_openwinby_click();
                })
            },
            // 按倍改量
            del_num: function () {
                if (this.num == 0 || this.num < 0) {
                    this.num = 0
                } else {
                    this.num--
                }
                app.$nextTick(function () {
                    hb_init_openwinby_click();
                })
            },
            add_num: function () {
                this.num++
                app.$nextTick(function () {
                    hb_init_openwinby_click();
                })
            },
            push_total_yaocai: function (name, id, drugsNo, salePrice, specs, storeId) { // 往总药材数组中添加数据
                var yaocai_item = {
                    userId: $api.getStorage("emp").userId,
                    drugsId: id,
                    name: name,
                    storeId: storeId,
                    drugsNo: drugsNo,
                    salePrice: salePrice,
                    quantity: "",
                    unit: "g",
                    specs: specs,
                    remark: "无备注",
                }
                this.total_yaocai.push(yaocai_item)
                this.yaocai = ""
                app.$nextTick(function () {
                    hb_init_openwinby_click();
                })
            },
            del_total_yaocai: function (index) { // 在总药材数组中删除指定下标数据
                this.total_yaocai.splice(index, 1)
                this.sent_data()
            },
            quding: function () {
                if (app.title_name == '') {
                    api.toast({
                        msg: '请填写常用方名称',
                        duration: 2000,
                        location: 'middle'
                    });

                } else {
                    post_ajax("doctor/frequent/save", {
                        userId: $api.getStorage("emp").userId,
                        name: app.title_name,
                        remark: String(app.string_total_yaocai),
                        frequentItemDtoList: app.total_yaocai,
                    }, function (ret, err) {
                        if (ret.code == 200) {
                            // alert(JSON.stringify(ret))
                            app.special_yaocai_zhezhao_fanan = false
                            toast("保存成功")
                        } else {
                            // alert(JSON.stringify(ret))
                            alert("保存失败，请检查您输入的是否正确")
                        }
                    })
                }
            }
        },
        watch: {
            num: function (val) {
                if (val < 0) {
                    this.num = 0
                }
            },
            yaocai: function (val) {
                if (val) {
                    get_ajax("doctor/list/search/drugs/page", {
                        storeId: api.pageParam.id,
                        // name: val,
                        pingyin: val,
                        page: 1,
                        pagesize: 10,
                    }, function (ret, err) {
                        // alert(JSON.stringify(ret))
                        // alert(JSON.stringify(err))
                        if (ret.code == 2000) {
                            app.searchReslut = ret.data.data
                            // app.searchReslut = [{
                            //     storeId: 1251765465,
                            //     drugsId: 1814011067,
                            //     name: "麻黄",
                            //     pingyin: "mahuang",
                            //     quantity: 10,
                            //     specs: "g",
                            //     salePrice: 10,
                            //     categoryId: 111,
                            //     categoryName: "中医"
                            // }]
                        }
                        // else {
                        //     toast("请求数据异常，请稍后再试！")
                        // }
                        // if (err) {
                        //     alert("网络不通畅，请稍后再试！")
                        // }
                        app.$nextTick(function () {
                            hb_init_openwinby_click();
                        })
                    })
                }
                this.num = 1
                this.add_total_quantity()
            },
            total_yaocai: function (val) {
                app.notice_tip = "请确认当前共" + app.total_yaocai.length + "味药材,共" + app.total_quantity + "g"
            }
        },
    })
    // 保存为常用方
    function save_yaocai_scheme() {
        // alert(JSON.stringify(app.total_yaocai))
        if (app.total_yaocai.length == 0) {
            toast("您还未输入任何处方药材")
            return
        } else {
            app.special_yaocai_zhezhao_fanan = true
            for (var i = 0; i < app.total_yaocai.length; i++) {
                var item = app.total_yaocai[i].name + app.total_yaocai[i].quantity + app.total_yaocai[i].unit
                app.string_total_yaocai.push(String(item))
            }
            // api.confirm({
            //     title: '存为常用方',
            //     msg: '确定存为常用方吗?',
            //     buttons: ['确定', '取消']
            // }, function (ret, err) {
            //     var index = ret.buttonIndex;
            //     if (index == 1) {
            //         post_ajax("doctor/frequent/save", {
            //             userId: $api.getStorage("emp").userId,
            //             name: "在" + api.pageParam.title + "保存的常用方",
            //             remark: String(app.string_total_yaocai),
            //             frequentItemDtoList: app.total_yaocai,
            //         }, function (ret, err) {
            //             if (ret.code == 200) {
            //                 // alert(JSON.stringify(ret))
            //                 toast("保存成功")
            //             } else {
            //                 // alert(JSON.stringify(ret))
            //                 alert("保存失败，请检查您输入的是否正确")
            //             }
            //         })
            //     } else {
            //         toast("取消保存")
            //     }

            // });
        }
        app.$nextTick(function () {
            hb_init_openwinby_click();
        })
    }

    function get_focus() {
        var val = app.total_yaocai.length
        setTimeout(function () {
            $(".yaocai_div_item div input").eq(val).val("")
            $(".yaocai_div_item div input").eq(val).focus()
            // $(".yaocai_div_item div input").eq(val).select()
        }, 200);
    }

    $("input").focus(function () {
        this.select();
    });
    document.onkeydown = function (e) { // 回车提交表单
        // 兼容FF和IE和Opera
        var theEvent = window.event || e;
        var code = theEvent.keyCode || theEvent.which || theEvent.charCode;
        if (code == 13) {
            $(".input input").focus()
        }
    }

    // 清空药材
    function del_yaocai() {
        api.confirm({
            title: '清空药材',
            msg: '确定清空全部药材吗?',
            buttons: ['确定', '取消']
        }, function (ret, err) {
            var index = ret.buttonIndex;
            if (index == 1) {
                app.total_yaocai = []
                app.total_quantity = 0
                // 发送数据给win
                api.sendEvent({
                    name: 'total_yaocai',
                    extra: {
                        total_yaocai: app.total_yaocai
                    }
                });
                toast("全部清除成功")
            } else {
                toast("取消清除")
            }

        });
        app.$nextTick(function () {
            hb_init_openwinby_click();
        })
    }

    // 确认开方
    function submit() {
        if (app.radio_cheched == false) {
            toast("请先勾选确认按钮")
        } else {
            app.special_yaocai_zhezhao = false
            toast("方案生成成功,请通知患者购药")
        }
        app.$nextTick(function () {
            hb_init_openwinby_click();
        })
    }
</script>